//
//  JDBaseVCLocationExtension.swift
//  DragonWallet
//
//  Created by volantPig on 2024/3/11.
//

import UIKit
import CoreLocation

class JDBaseVCLocationExtension: NSObject {

}

// MARK: 定位
extension JDBaseViewController {
    // MARK: 写一个定位方法，包含一个block,block直接写在方法参数里，不额外定义type，block主要返回经纬度信息，是否还需要其他信息，后期再额外添加处理
    
    func getCurrentLocation() {
        printLog("当前开始获取定位")
        let locationManager = CLLocationManager()
        locationManager.requestWhenInUseAuthorization()
        locationManager.delegate = self
        locationManager.startUpdatingLocation()
    }
    
}

extension JDBaseViewController: CLLocationManagerDelegate {
    
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        if let currentLocation = locations.last {
            self.currentLongitude = currentLocation.coordinate.longitude
            self.currentLatitude = currentLocation.coordinate.latitude
            
            printLog("当前经度:\(currentLocation.coordinate.longitude)")
            printLog("当前纬度:\(currentLocation.coordinate.latitude)")
            manager.stopUpdatingLocation()
        }
    }
}
